package cn.csg.iotplatform.module.system.convert;

import cn.csg.iotplatform.framework.common.util.collection.CollectionUtils;
import cn.csg.iotplatform.framework.common.util.collection.MapUtils;
import cn.csg.iotplatform.framework.common.util.object.BeanUtils;
import cn.csg.iotplatform.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO;
import cn.csg.iotplatform.module.system.dal.dataobject.permission.MenuDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

@Mapper
public interface MenuConvert {

    MenuConvert INSTANCE = Mappers.getMapper(MenuConvert.class);

    default List<MenuSimpleRespVO> convertSimpleList(List<MenuDO> list, Map<Long, MenuDO> menuMap) {
        return CollectionUtils.convertList(list, menu -> {
            MenuSimpleRespVO menuVo = BeanUtils.toBean(menu, MenuSimpleRespVO.class);
            MapUtils.findAndThen(menuMap, menu.getId(), menuVO -> menuVo.setIsGray(0));
            return menuVo;
        });
    }
}
